package com.easybuy.service.ProductService;

import com.easybuy.Tools.Page;
import com.easybuy.dao.ProductMapper;
import com.easybuy.pojo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    public Page selectProducts(Map map) {
        Page page=(Page)map.get("page");
        Integer pageCount=productMapper.selectCount(map);
        if(pageCount!=null)page.setPageCount(pageCount);
        List list=productMapper.selectProducts(map);
        if(list!=null)page.setList(list);
        return page;
    }

    public Product selectProductById(int id) {
        return productMapper.selectProductById(id);
    }

    @Override
    public Product selectProductByName(String name) {
        return productMapper.selectProductByName(name);
    }

    public Page allProducts(Page page) {
        page.setPageCount(productMapper.allCount());
        page.setList(productMapper.allProducts(page));
        return page;
    }

    public int addProduct(Product product) {
        return productMapper.addProduct(product);
    }

    public int deleProduct(int id) {
        return productMapper.deleProduct(id);
    }

    public int updateProduct(Product product) {
        return productMapper.updateProduct(product);
    }


}
